<template>
  <view class="video--com" :style="'padding:' + ( radioTC === 2 ? 20 : 0 ) + 'rpx'">
    <video :src="radio === 1 ? video : videoLink"
      :style="'width:' + videowidth + 'rpx;height:' + videoheight + 'rpx'" :poster="poster"></video>
  </view>
</template>

<script lang="ts">
  import {
    Component,
    Vue,
    Prop,
    Watch
  } from 'vue-property-decorator'


  @Component({})
  export default class VideoCom extends Vue {
    @Prop({
      type: Object
    })
    decoretionProperties: any
    @Watch("decoretionProperties")
    onPropUpdate() {
      this.getProperties(this.decoretionProperties)
      this.getvideo();
    }

    VideoCom: string = "";
    height: string = "";
    link: any = {};
    poster: string = "";
    radio: number = 1;
    radioBL: number = 1;
    radioTC: number = 1;
    video: string = "";
    videoLink: string = "";
    width: string = "";
    videowidth: number = 750;
    videoheight: number = 0;

    mounted() {
      this.getProperties(this.decoretionProperties)
    }

    getProperties(formdata) {
      this.VideoCom = formdata.VideoCom
      this.height = formdata.height
      this.link = formdata.link
      this.poster = formdata.poster
      this.radio = formdata.radio
      this.radioBL = formdata.radioBL
      this.radioTC = formdata.radioTC
      this.video = formdata.video
      this.videoLink = formdata.videoLink
      this.width = formdata.width
      this.getvideo();
    }

    getvideo() {
      if (this.radioTC === 2) {
        this.videowidth = 710
      }
      if (this.radioBL === 1) {
        this.videoheight = (this.videowidth / 16) * 9
      }
      if (this.radioBL === 2) {
        this.videoheight = this.videowidth
      }
      if (this.radioBL === 3) {
        const url = this.radio === 1 ? this.video : this.videoLink;
        // const getVideoInfo = this.getVideoInfo;
        uni.downloadFile({
          //需要先下载文件获取临时文件路径 单个文件大小不得超过50M
          url: url,
          success: (res1: any) => {
            this.getVideoInfo(res1.tempFilePath);
          },
        });
      }
    }

    getVideoInfo(url) {
      uni.getVideoInfo({
        src: url,
        success: res => {
          const bit = res.height / res.width;
          this.videoheight = this.videowidth * bit
        },
        fail(err) {
          console.log(err);
        },
      });
    }
  }
</script>

<style lang="scss" scoped>
  .video--com {
    width: 100%;
    background-color: #fff;
  }
</style>